﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ePhoneBook.Custom
{
    public class MetaDataProvider : DataAnnotationsModelMetadataProvider
    {
        // Summary:
        //     Gets the metadata for the specified property.
        //
        // Parameters:
        //   attributes:
        //     The attributes.
        //
        //   containerType:
        //     The type of the container.
        //
        //   modelAccessor:
        //     The model accessor.
        //
        //   modelType:
        //     The type of the model.
        //
        //   propertyName:
        //     The name of the property.
        //
        // Returns:
        //     The metadata for the property.
        protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
        {
            var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
            var additionalValues = attributes.OfType<AdditionalHtml>().FirstOrDefault();
            if (additionalValues != null)
            {
                metadata.AdditionalValues.Add("AdditionalHtml", additionalValues);
            }
            return metadata;
        }
    }
}